home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gnugo1_1.lha / gnugo / findnext.c < prev    next >
C/C++ Source or Header  |  1989-03-07  |  4KB  |  189 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35.  
  36. #include <stdio.h>
  37.  
  38. #define EMPTY 0
  39.  
  40. extern unsigned char p[19][19], ma[19][19];
  41. extern int mymove;
  42. extern int lib;
  43.  
  44. findnextmove(m, n, i, j, val, minlib)
  45. /* find new move i, j from group containing m, n */
  46. int m, n, *i, *j, *val, minlib;
  47.  {
  48.   int ti, tj, tval;
  49.   int found = 0;
  50.  
  51.   *i = -1;   *j = -1;    *val = -1;
  52. /* mark current position */
  53.   ma[m][n] = 1;
  54.  
  55. /* check North neighbor */
  56.   if (m != 0)
  57.      if (p[m - 1][n] == EMPTY)
  58.       {
  59.        ti = m - 1;
  60.        tj = n;
  61.        lib = 0;
  62.        countlib(ti, tj, mymove);
  63.        tval = fval(lib, minlib);
  64.        found = 1;
  65.       }
  66.      else
  67.        if ((p[m - 1][n] == mymove) && !ma[m - 1][n])
  68.      if (findnextmove(m - 1, n, &ti, &tj, &tval, minlib))
  69.         found = 1;
  70.  
  71.   if (found)
  72.     {
  73.      found = 0;
  74.      if (tval > *val)
  75.        {
  76.     *val = tval;
  77.     *i = ti;
  78.     *j = tj;
  79.       }
  80.      if (minlib == 1) return 1;
  81.    }
  82.  
  83. /* check South neighbor */
  84.   if (m != 18)
  85.      if (p[m + 1][n] == EMPTY)
  86.       {
  87.        ti = m + 1;
  88.        tj = n;
  89.        lib = 0;
  90.        countlib(ti, tj, mymove);
  91.        tval = fval(lib, minlib);
  92.        found = 1;
  93.       }
  94.      else
  95.        if ((p[m + 1][n] == mymove) && !ma[m + 1][n])
  96.       if (findnextmove(m + 1, n, &ti, &tj, &tval, minlib))
  97.          found = 1;
  98.  
  99.   if (found)
  100.     {
  101.      found = 0;
  102.      if (tval > *val)
  103.        {
  104.     *val = tval;
  105.     *i = ti;
  106.     *j = tj;
  107.       }
  108.      if (minlib == 1) return 1;
  109.    }
  110.  
  111. /* check West neighbor */
  112.   if (n != 0)
  113.      if (p[m][n - 1] == EMPTY)
  114.       {
  115.        ti = m;
  116.        tj = n - 1;
  117.        lib = 0;
  118.        countlib(ti, tj, mymove);
  119.        tval = fval(lib, minlib);
  120.        found = 1;
  121.       }
  122.      else
  123.        if ((p[m][n - 1] == mymove) && !ma[m][n - 1])
  124.       if (findnextmove(m, n - 1, &ti, &tj, &tval, minlib))
  125.           found = 1;
  126.  
  127.   if (found)
  128.     {
  129.      found = 0;
  130.      if (tval > *val)
  131.        {
  132.     *val = tval;
  133.     *i = ti;
  134.     *j = tj;
  135.       }
  136.      if (minlib == 1) return 1;
  137.    }
  138.  
  139. /* check East neighbor */
  140.   if (n != 18)
  141.      if (p[m][n + 1] == EMPTY)
  142.       {
  143.        ti = m;
  144.        tj = n + 1;
  145.        lib = 0;
  146.        countlib(ti, tj, mymove);
  147.        tval = fval(lib, minlib);
  148.        found = 1;
  149.       }
  150.      else
  151.        if ((p[m][n + 1] == mymove) && !ma[m][n + 1])
  152.       if (findnextmove(m, n + 1, &ti, &tj, &tval, minlib))
  153.           found = 1;
  154.  
  155.   if (found)
  156.     {
  157.      found = 0;
  158.      if (tval > *val)
  159.        {
  160.     *val = tval;
  161.     *i = ti;
  162.     *j = tj;
  163.       }
  164.      if (minlib == 1) return 1;
  165.    }
  166.  
  167.  if (*val > 0)    /* found next move */
  168.     return 1;
  169.  else    /* next move failed */
  170.     return 0;
  171. }  /* end findnextmove */
  172.  
  173.  
  174. fval(newlib, minlib)
  175. /* evaluate new move */
  176. int newlib, minlib;
  177. {
  178.  int k, val;
  179.  
  180.  if (newlib <= minlib)
  181.     val = -1;
  182.  else
  183.    {
  184.     k = newlib - minlib;
  185.     val = 40 + (k - 1) * 50 / (minlib * minlib * minlib);
  186.   }
  187.  return val;
  188. }  /* end fval */
  189.